package com.leonwoodstudio.eventdetectionclient.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by win7 on 2017/4/9.
 */
public class DatabaseHelper extends SQLiteOpenHelper {
    private static final int VERSION = 1;
    private static final String NAME = "EventDetectionClientDB";
    public static final String EVENT_HISTORY_TABLE_NAME = "EventHistoryTable";
    public DatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,
                          int version) {
        super(context, name, factory, version);
        // TODO Auto-generated constructor stub
    }
    public DatabaseHelper(Context context) {
        this(context, NAME, null, VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("create table " + EVENT_HISTORY_TABLE_NAME +
                "(_id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "url TEXT, pic_name TEXT, date TEXT, camera_idx TEXT, lane_inx TEXT, " +
                "event_type TEXT, coordinate_x TEXT, coordinate_y TEXT)");
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        String sql = "drop table if exists " + EVENT_HISTORY_TABLE_NAME;
        db.execSQL(sql);
        onCreate(db);
    }
}
